﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FilStartUps.FILAPI;
using FilStartUps.Helper;

namespace FilStartUps.Controls
{
    public partial class FilStartUps_LatestArticles : System.Web.UI.UserControl
    {
        private void GetLatestArticles()
        {
            try
            {
                var latest = FilStartUpsAPI.GetLatestArticles();
                dlFilStartUps_LatestArticles.DataSource = latest;
                dlFilStartUps_LatestArticles.DataBind();
            }
            catch (Exception)
            {

            }
        }

        public string Truncate(string Description)
        {
            string desc;

            try
            {
                desc = HtmlRemoval.StripTagsCharArray(Description.ToString().Substring(0, 200) + "...");
            }
            catch (Exception)
            {
                desc = HtmlRemoval.StripTagsCharArray(Description);
            }

            return desc;
        }

        //Response.Redirect("Articles.aspx");
        //Article.aspx;
        //ArticlesArhieves.aspx
        protected void dlFilStartUps_LatestArticles_ItemCommand(object sender, DataListCommandEventArgs e)
        {
            if (e.CommandName == "SelectRow")
            {
                LinkButton lnkposttitle = (LinkButton)dlFilStartUps_LatestArticles.Items[e.Item.ItemIndex].FindControl("filstartups_");
                Label lbpostidPK = (Label)dlFilStartUps_LatestArticles.Items[e.Item.ItemIndex].FindControl("postidPK");
                Response.Redirect("~/Article.aspx?p=" + lbpostidPK.Text);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetLatestArticles();
            }
        }

        protected void rssbtnarticles_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/rss.aspx?ID=1");
        }
    }
}